473,434 Members | 1,438 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

VB.NET reading CSV files (odbc or oledb)

Hiyo,
I'm trying to import a CSV file into a datatable using either ODBC or
OLEDB. One of the columns contains an IP Address. For some reason,
the IP address will not display correctly. All of the other
information in the CSV is accurate.

For example,
10.80.34.100 displays as 10.8034. All the IPs in the column are
displayed like this.

I'm not sure what is causing this error, I have tried using odbc and
the oledb drivers to load the csv and they both seem to cause that so
I'm not sure what I'm doing wrong. When I put quotes around the IP
addresses this fixes the issue, however I don't really want to use
quotes since I'm using commas for a seperate parsing script.

The code I use to load the data is (Right now it's using ODBC, the
commented codes are the oledb connection):

Dim sConnectionString As String = "Driver={Microsoft Text Driver
(*.txt; *.csv)};Dbq=" & Directory & ";Extensions=asc,csv,tab,txt;"
Dim objConn As New Odbc.OdbcConnection(sConnectionString)
'Dim sConnectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Directory &
";Extended Properties=""text;HDR=Yes;FMT=CSVDelimited"""
'Dim objConn As New
OleDb.OleDbConnection(sConnectionString)
objConn.Open()

Dim objCmdSelect As New Odbc.OdbcCommand("SELECT * FROM " &
FileName, objConn)
Dim objAdapter1 As New Odbc.OdbcDataAdapter

' Dim objCmdSelect As New OleDb.OleDbCommand("SELECT * FROM
" & FileName, objConn)
'Dim objAdapter1 As New OleDb.OleDbDataAdapter()
objAdapter1.SelectCommand = objCmdSelect

Dim objDataset1 As New DataSet()
objAdapter1.Fill(objDataset1, "Table1")
DataGridView1.DataSource =
objDataset1.Tables(0).DefaultView
objConn.Close()
An example line of the CSV is:
10.80.34.116,Name,Location

The datagridview would then display (columns seperated on newlines):
10.8034
Name
Location

Apr 24 '06 #1
5 23141
cj
It's seeing the ip address as a number. Somehow you need to designate
that it is a character field. Adding the "s around it does that but
there is probably another way. I'll be watching to see the solution myself.

Jesse Albert wrote:
Hiyo,
I'm trying to import a CSV file into a datatable using either ODBC or
OLEDB. One of the columns contains an IP Address. For some reason,
the IP address will not display correctly. All of the other
information in the CSV is accurate.

For example,
10.80.34.100 displays as 10.8034. All the IPs in the column are
displayed like this.

I'm not sure what is causing this error, I have tried using odbc and
the oledb drivers to load the csv and they both seem to cause that so
I'm not sure what I'm doing wrong. When I put quotes around the IP
addresses this fixes the issue, however I don't really want to use
quotes since I'm using commas for a seperate parsing script.

The code I use to load the data is (Right now it's using ODBC, the
commented codes are the oledb connection):

Dim sConnectionString As String = "Driver={Microsoft Text Driver
(*.txt; *.csv)};Dbq=" & Directory & ";Extensions=asc,csv,tab,txt;"
Dim objConn As New Odbc.OdbcConnection(sConnectionString)
'Dim sConnectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Directory &
";Extended Properties=""text;HDR=Yes;FMT=CSVDelimited"""
'Dim objConn As New
OleDb.OleDbConnection(sConnectionString)
objConn.Open()

Dim objCmdSelect As New Odbc.OdbcCommand("SELECT * FROM " &
FileName, objConn)
Dim objAdapter1 As New Odbc.OdbcDataAdapter

' Dim objCmdSelect As New OleDb.OleDbCommand("SELECT * FROM
" & FileName, objConn)
'Dim objAdapter1 As New OleDb.OleDbDataAdapter()
objAdapter1.SelectCommand = objCmdSelect

Dim objDataset1 As New DataSet()
objAdapter1.Fill(objDataset1, "Table1")
DataGridView1.DataSource =
objDataset1.Tables(0).DefaultView
objConn.Close()
An example line of the CSV is:
10.80.34.116,Name,Location

The datagridview would then display (columns seperated on newlines):
10.8034
Name
Location

Apr 24 '06 #2
You can use a schema.ini file to attempt to change this behavior,
http://support.microsoft.com/?kbid=210073 . If you get tired of the
crazyness with these drivers, you can optionally try using my parser
that I sell because of the awkwardness of these configurations,
http://www.csvreader.com .

Bruce Dunwiddie

cj wrote:
It's seeing the ip address as a number. Somehow you need to designate
that it is a character field. Adding the "s around it does that but
there is probably another way. I'll be watching to see the solution myself.

Jesse Albert wrote:
Hiyo,
I'm trying to import a CSV file into a datatable using either ODBC or
OLEDB. One of the columns contains an IP Address. For some reason,
the IP address will not display correctly. All of the other
information in the CSV is accurate.

For example,
10.80.34.100 displays as 10.8034. All the IPs in the column are
displayed like this.

I'm not sure what is causing this error, I have tried using odbc and
the oledb drivers to load the csv and they both seem to cause that so
I'm not sure what I'm doing wrong. When I put quotes around the IP
addresses this fixes the issue, however I don't really want to use
quotes since I'm using commas for a seperate parsing script.

The code I use to load the data is (Right now it's using ODBC, the
commented codes are the oledb connection):

Dim sConnectionString As String = "Driver={Microsoft Text Driver
(*.txt; *.csv)};Dbq=" & Directory & ";Extensions=asc,csv,tab,txt;"
Dim objConn As New Odbc.OdbcConnection(sConnectionString)
'Dim sConnectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Directory &
";Extended Properties=""text;HDR=Yes;FMT=CSVDelimited"""
'Dim objConn As New
OleDb.OleDbConnection(sConnectionString)
objConn.Open()

Dim objCmdSelect As New Odbc.OdbcCommand("SELECT * FROM " &
FileName, objConn)
Dim objAdapter1 As New Odbc.OdbcDataAdapter

' Dim objCmdSelect As New OleDb.OleDbCommand("SELECT * FROM
" & FileName, objConn)
'Dim objAdapter1 As New OleDb.OleDbDataAdapter()
objAdapter1.SelectCommand = objCmdSelect

Dim objDataset1 As New DataSet()
objAdapter1.Fill(objDataset1, "Table1")
DataGridView1.DataSource =
objDataset1.Tables(0).DefaultView
objConn.Close()
An example line of the CSV is:
10.80.34.116,Name,Location

The datagridview would then display (columns seperated on newlines):
10.8034
Name
Location


Apr 24 '06 #3
One way to see what is causing the problem is to try (as a test) importing
the CSV file into a Access Database table, using Access itself. If it does
the same thing there, you will at least get a good error message.
Otherwise,,,,,,,
In your connection string in your code change this: FMT=CSVDelimited"""
to: FTM=Delimited\"""
The rest of your code looks fine. Just did a test making the changes I
mentioned and it works fine.
james

"Jesse Albert" <Je*********@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
Hiyo,
I'm trying to import a CSV file into a datatable using either ODBC or
OLEDB. One of the columns contains an IP Address. For some reason,
the IP address will not display correctly. All of the other
information in the CSV is accurate.

For example,
10.80.34.100 displays as 10.8034. All the IPs in the column are
displayed like this.

I'm not sure what is causing this error, I have tried using odbc and
the oledb drivers to load the csv and they both seem to cause that so
I'm not sure what I'm doing wrong. When I put quotes around the IP
addresses this fixes the issue, however I don't really want to use
quotes since I'm using commas for a seperate parsing script.

The code I use to load the data is (Right now it's using ODBC, the
commented codes are the oledb connection):

Dim sConnectionString As String = "Driver={Microsoft Text Driver
(*.txt; *.csv)};Dbq=" & Directory & ";Extensions=asc,csv,tab,txt;"
Dim objConn As New Odbc.OdbcConnection(sConnectionString)
'Dim sConnectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Directory &
";Extended Properties=""text;HDR=Yes;FMT=CSVDelimited"""
'Dim objConn As New
OleDb.OleDbConnection(sConnectionString)
objConn.Open()

Dim objCmdSelect As New Odbc.OdbcCommand("SELECT * FROM " &
FileName, objConn)
Dim objAdapter1 As New Odbc.OdbcDataAdapter

' Dim objCmdSelect As New OleDb.OleDbCommand("SELECT * FROM
" & FileName, objConn)
'Dim objAdapter1 As New OleDb.OleDbDataAdapter()
objAdapter1.SelectCommand = objCmdSelect

Dim objDataset1 As New DataSet()
objAdapter1.Fill(objDataset1, "Table1")
DataGridView1.DataSource =
objDataset1.Tables(0).DefaultView
objConn.Close()
An example line of the CSV is:
10.80.34.116,Name,Location

The datagridview would then display (columns seperated on newlines):
10.8034
Name
Location

Apr 24 '06 #4
Forgot to mention one other thing, your date in the CSV file needs to be
enclosed in quotes:
"IPADDRESS","NAME","LOCATION"
"192.168.0.3","JOE","HERE"

otherwise, if you leave off the quotes, Access will strip off everything
past the second decimal point ( .0.3)
james

"Jesse Albert" <Je*********@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
Hiyo,
I'm trying to import a CSV file into a datatable using either ODBC or
OLEDB. One of the columns contains an IP Address. For some reason,
the IP address will not display correctly. All of the other
information in the CSV is accurate.

For example,
10.80.34.100 displays as 10.8034. All the IPs in the column are
displayed like this.

I'm not sure what is causing this error, I have tried using odbc and
the oledb drivers to load the csv and they both seem to cause that so
I'm not sure what I'm doing wrong. When I put quotes around the IP
addresses this fixes the issue, however I don't really want to use
quotes since I'm using commas for a seperate parsing script.

The code I use to load the data is (Right now it's using ODBC, the
commented codes are the oledb connection):

Dim sConnectionString As String = "Driver={Microsoft Text Driver
(*.txt; *.csv)};Dbq=" & Directory & ";Extensions=asc,csv,tab,txt;"
Dim objConn As New Odbc.OdbcConnection(sConnectionString)
'Dim sConnectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Directory &
";Extended Properties=""text;HDR=Yes;FMT=CSVDelimited"""
'Dim objConn As New
OleDb.OleDbConnection(sConnectionString)
objConn.Open()

Dim objCmdSelect As New Odbc.OdbcCommand("SELECT * FROM " &
FileName, objConn)
Dim objAdapter1 As New Odbc.OdbcDataAdapter

' Dim objCmdSelect As New OleDb.OleDbCommand("SELECT * FROM
" & FileName, objConn)
'Dim objAdapter1 As New OleDb.OleDbDataAdapter()
objAdapter1.SelectCommand = objCmdSelect

Dim objDataset1 As New DataSet()
objAdapter1.Fill(objDataset1, "Table1")
DataGridView1.DataSource =
objDataset1.Tables(0).DefaultView
objConn.Close()
An example line of the CSV is:
10.80.34.116,Name,Location

The datagridview would then display (columns seperated on newlines):
10.8034
Name
Location

Apr 24 '06 #5
Let me try to type this a bit slower this time, your DATA in the CSV file
needs to be enclosed in quotes:
(then the rest of my example)
Sorry about that, been several hours since my last cup of coffee and I'm
having accuracy problems now!!! :-)
james

"james" <jj***************@earthlink.net> wrote in message
news:ej**************@TK2MSFTNGP05.phx.gbl...
Forgot to mention one other thing, your date in the CSV file needs to be
enclosed in quotes:
"IPADDRESS","NAME","LOCATION"
"192.168.0.3","JOE","HERE"

otherwise, if you leave off the quotes, Access will strip off everything
past the second decimal point ( .0.3)
james

"Jesse Albert" <Je*********@gmail.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
Hiyo,
I'm trying to import a CSV file into a datatable using either ODBC or
OLEDB. One of the columns contains an IP Address. For some reason,
the IP address will not display correctly. All of the other
information in the CSV is accurate.

For example,
10.80.34.100 displays as 10.8034. All the IPs in the column are
displayed like this.

I'm not sure what is causing this error, I have tried using odbc and
the oledb drivers to load the csv and they both seem to cause that so
I'm not sure what I'm doing wrong. When I put quotes around the IP
addresses this fixes the issue, however I don't really want to use
quotes since I'm using commas for a seperate parsing script.

The code I use to load the data is (Right now it's using ODBC, the
commented codes are the oledb connection):

Dim sConnectionString As String = "Driver={Microsoft Text Driver
(*.txt; *.csv)};Dbq=" & Directory & ";Extensions=asc,csv,tab,txt;"
Dim objConn As New Odbc.OdbcConnection(sConnectionString)
'Dim sConnectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Directory &
";Extended Properties=""text;HDR=Yes;FMT=CSVDelimited"""
'Dim objConn As New
OleDb.OleDbConnection(sConnectionString)
objConn.Open()

Dim objCmdSelect As New Odbc.OdbcCommand("SELECT * FROM " &
FileName, objConn)
Dim objAdapter1 As New Odbc.OdbcDataAdapter

' Dim objCmdSelect As New OleDb.OleDbCommand("SELECT * FROM
" & FileName, objConn)
'Dim objAdapter1 As New OleDb.OleDbDataAdapter()
objAdapter1.SelectCommand = objCmdSelect

Dim objDataset1 As New DataSet()
objAdapter1.Fill(objDataset1, "Table1")
DataGridView1.DataSource =
objDataset1.Tables(0).DefaultView
objConn.Close()
An example line of the CSV is:
10.80.34.116,Name,Location

The datagridview would then display (columns seperated on newlines):
10.8034
Name
Location


Apr 25 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Andreas Lauffer | last post by:
I changed from Access97 to AccessXP and I have immense performance problems. Details: - Access XP MDB with Jet 4.0 ( no ADP-Project ) - Linked Tables to SQL-Server 2000 over ODBC I used...
6
by: serge calderara | last post by:
Dear all, Does any one have any idea why an sql statment with INNER JOIN syntax is working well with odbcprovider but not with Oledbprovider when accessing an access 2000 database? here is...
2
by: Roland Hall | last post by:
I have two(2) issues. I'm experiencing a little difficulty and having to resort to a work around. I already found one bug, although stated the bug was only in ODBC, which I'm not using. It...
14
by: Roland Hall | last post by:
I have two(2) issues. I'm experiencing a little difficulty and having to resort to a work around. I already found one bug, although stated the bug was only in ODBC, which I'm not using. It...
3
by: Roland Hall | last post by:
Three times the charm? Sorry for the repost. Trying to get my account right. I have two(2) issues. I'm experiencing a little difficulty and having to resort to a work around. I already...
4
by: Andreas Lauffer | last post by:
Can anyone tell me advantages / disadvantages of DataDirect Server Wire ODBC-driver? Any experiences? What about redistribution? Andreas Lauffer, easySoft. GmbH, Germany
1
by: JoeBobHankey | last post by:
Background: - I'm running MSDE 2000 (not client tools, stored procedure capability, etc). This may change, but not in the first part of development. - My Access file is an Access 2002 project...
3
by: James | last post by:
Hi, I'm importing some csv files with this code /// start of code snippet int iPos = strFileName.LastIndexOf(@"\"); string strPath = strFileName.Substring(0,iPos); string strSelect =...
9
by: dba123 | last post by:
I need some help and direction on what classes and an example or two (article) on how to read an Excel Worksheet and insert one column into a database table column. I am using .NET 2.0 only. What...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.